/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/10 10:31
  *
  * @file       hd_oled.h
  * @brief      Header file of OLED hardware driver.
  *
  * @note       This file contains the OLED object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date           Author       Notes
  *   2024/6/10      Chris        the first version
  *
  ******************************************************************************
  */

#ifndef JLC_SKY_OLED_H
#define JLC_SKY_OLED_H

#include "air001xx.h"
#include "air001xx_ll_gpio.h"
#include "hd_oled_protocol.h"
#include "hd_oled_font.h"
#include "drivers.h"

/**
 * The mode of the font displayed on the OLED.
 */
#define OLED_MODE_NEGATIVE  0           /* OLED negative display, light up the background.  */
#define OLED_MODE_POSITIVE  1           /* OLED positive display, light up the content.     */

/**
 * The size of the font displayed on the OLED.
 */
#define OLED_SIZE_12        12          /* ascii 12x6, chinese 12x12                        */
#define OLED_SIZE_16        16          /* ascii 16x8, chinese 16x16                        */
#define OLED_SIZE_24        24          /* ascii 24x12, chinese 24x24                       */

#define OLED_I2C_ADDRESS    0x3C        /* OLED address just for IIC.                       */
#define OLED_I2C_CMD        0x00        /* OLED send a connmad.                             */
#define OLED_I2C_DATA       0x40        /* OLED send a data.                                */

typedef struct OLEDDef OLED;

struct OLEDDef {
    uint8_t size;                       /* The font size can be 12/16/24.                   */
    uint8_t mode;                       /* The font mode can be negative or positive.       */
    OLEDProtocol *oledProtocol;         /* The protocol of OLED communication(IIC/SPI).     */
    OLEDFont *oledFont;                 /* The oled font storage.                           */

    void (*init)(OLED *this);

    void (*clear)(OLED *this);

    void (*full)(OLED *this);

    void (*refresh)(OLED *this);


    uint8_t (*showChar)(OLED *this, uint8_t x, uint8_t y, char chr);

    void (*showString)(OLED *this, uint8_t x, uint8_t y, char *str);

    void (*showNum)(OLED *this, uint8_t x, uint8_t y, uint32_t num, uint8_t len);

    void (*showSignedNum)(OLED *this, uint8_t x, uint8_t y, int32_t num, uint8_t len);

    void (*showHexNum)(OLED *this, uint8_t x, uint8_t y, uint32_t num, uint8_t len);

    void (*showBinNum)(OLED *this, uint8_t x, uint8_t y, uint32_t num, uint8_t len);

    void (*showFloatNum)(OLED *this, uint8_t x, uint8_t y, float num, uint8_t len);

    uint8_t (*showChinese)(OLED *this, uint8_t x, uint8_t y, char *cn);

    void (*showImage)(OLED *this, uint8_t x, uint8_t y,
                      uint8_t width, uint8_t height, const uint8_t *dotMatrix);

    void (*printf)(OLED *this, uint8_t x, uint8_t y, char *format, ...);


    void (*drawPoint)(uint8_t x, uint8_t y, uint8_t point);

};

extern const struct OLEDClass {
    OLED *(*build)(OLEDProtocol *oledProtocol, OLEDFont *oledFont);
} OLEDBuilder;


#endif // JLC_SKY_OLED_H
